<template>
	<view>
		<watermark></watermark>
		<view v-if="page_is_show" class="remarkForm">
			<view v-if="is_edit == true">
				<textarea class="remarkForm-textarea" :style="'width:' + textareaW + 'px;height: ' + textareaH + 'px;'" placeholder="修改群介绍" type="text" v-model="form.content" :adjust-position="false" ></textarea>
			</view>
			<text v-else>
				{{form.content}}
			</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			form:{
				groupId: '',
				content: ''
			},
			is_edit: false,
			detail: [],
			page_is_show: false,
			textareaW: 0,
			textareaH: 0
		};
	},
	onLoad(e) {
		var self = this;
		self.form.groupId = e.groupId;
		uni.getSystemInfo({
			success: function (res) {
				self.textareaW = res.windowWidth - 40;
				self.textareaH = res.safeArea.height - 30;
			}
		});
	},
	onReady(){
		this.$fc.setTitleNViewBtns(0,'');
	},
	onShow(){
		this.getInfo(this.form.groupId);
	},
	methods: {
		getInfo(e) {
			this.$http.request({
				url: '/group/getInfo/?id=' + e,
				success: res => {
					if (res.data.code == 200) {
						var detail = res.data.data;
						this.form.content = detail.content;
						this.detail = detail;
						if(detail.user_type == 'root' || detail.user_type == 'manage'){
							this.$fc.setTitleNViewBtns(0,'完成');
							this.is_edit = true;
						}else{
							this.$fc.setTitleNViewBtns(0,'');
							this.is_edit = false;
						}
						this.page_is_show = true;
					}
				}
			});
		},
		subform(e) {
			var rules = {
				content: {
					rules: [{
						checkType: "required",
						errorMsg: "请填写内容"
					}]
				}
			};
			var formData = JSON.parse(JSON.stringify(this.form));
			var checkRes = this.$zmmFormCheck.check(formData, rules);
			if (checkRes) {
    			uni.showLoading({
    				title: '提交中'
    			});
				this.$http.request({
					url: '/group/editGroupContent',
					method: 'POST',
					data:JSON.stringify(formData),
					success: (res) => {
						if (res.data.code == 200) {
							uni.navigateBack({
								delta: 1
							}).then(()=>{
								
							})
						}
					}
				});
			} else {
				uni.showToast({
					title: this.$zmmFormCheck.error,
					icon: "none",
					position: 'bottom'
				});
			}
		}
	},
	onNavigationBarButtonTap(e) {
		switch (e.index) {
			case 0:
				if(this.detail.user_type == 'root' || this.detail.user_type == 'manage'){
					this.subform()
				}else{
					// uni.showToast({
					// 	title: '只有群主及管理员可以编辑群介绍',
					// 	icon: 'none'
					// });
				}
				break;
			default:
				break;
		}
	},
};
</script>

<style scoped lang="scss">
	.remarkForm{
		margin: 10px;
	}
	.remarkForm-textarea{
		border-radius: 12rpx;
		background-color: #F7F7F7;
		line-height: 48rpx;
		padding: 5px 10px;
	}
</style>
